我在 srv1 上写了一个 asmx webSerivce。 我在srv2上写了一个bll project of an asp.net(原文:一个asp.net)项目。 两者都托管在同一个网络域下
我想从asp.net的bll项目中调用asmx(原文:asp.net(c#) code behind)
1) 我添加了一个 Web 引用,但找不到任何教程如何真正调用引用的服务。
我试过:
private void GetTemplateComponentsData()
{
var service = new ServiceReference.GetTemplateParamSoapClient();
TemplateParamsKeyValue[] responsArray = service.GetTemplatesParamsPerId(id);
foreach (var pair in responsArray)
{
TemplateComponentsData.Add(pair.Key, pair.Value);
}
}
但执行第一行时出现如下错误: 在 ServiceModel 客户端配置部分找不到引用协定“ServiceReference.GetTemplateParamSoap”的默认终结点元素。这可能是因为没有找到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。
我错过了什么?
2) 我计划将 asp.net proj 和 asmx 一起从一个域迁移到另一个域。 有什么方法可以相对地引用这个 webservice 吗?
最佳答案
好的,让我尝试重新表述您的场景以确保我做对了:
第一步是通过指向 ASMX 服务的 WSDL 添加对 ASP.NET 应用程序的服务引用:
这会做两件事:
它将修改您的 web.config 并包含客户端端点:
<client>
<endpoint address="http://ws.cdyne.com/NotifyWS/phonenotify.asmx"
binding="basicHttpBinding" bindingConfiguration="PhoneNotifySoap"
contract="ServiceReference1.PhoneNotifySoap" name="PhoneNotifySoap" />
<endpoint address="http://ws.cdyne.com/NotifyWS/phonenotify.asmx"
binding="customBinding" bindingConfiguration="PhoneNotifySoap12"
contract="ServiceReference1.PhoneNotifySoap" name="PhoneNotifySoap12" />
</client>
现在,当您想要从您的应用程序调用此服务时,您必须选择要使用的端点:
using (var client = new ServiceReference1.PhoneNotifySoapClient("PhoneNotifySoap"))
{
var result = client.GetVersion();
}
现在只需将我的代码片段替换为您的实际服务名称即可。
关于c# - 从 C# 服务器端调用 asmx : endpoint element matching this contract could be found in the client element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7510953/