调用ASMX从C#服务器端:匹配这份合同终结点元素可以在客户端元素中找到 [英] calling asmx from c# server side: endpoint element matching this contract could be found in the client element
问题描述
我写了一个SRV1 ASMX webSerivce。
我写了一个asp.net (原文:一个asp.net)的 BLL项目上SRV2项目。
两者都是在相同的网站域名托管
I wrote an asmx webSerivce on srv1. I wrote a bll project of an asp.net (original text: an asp.net) project on srv2. Both are hosted under the same web domain
我想从asp.net 的 BLL项目调用ASMX。(原文:asp.net(C#)code后面)
I want to call the asmx from the bll project of the asp.net (original text: asp.net(c#) code behind).
1)我添加的Web引用,但找不到任何教程如何真正调用引用的服务。
1) I added a web reference, but couldn't find any tutorial how to really call the referenced service.
我曾尝试:
private void GetTemplateComponentsData()
{
var service = new ServiceReference.GetTemplateParamSoapClient();
TemplateParamsKeyValue[] responsArray = service.GetTemplatesParamsPerId(id);
foreach (var pair in responsArray)
{
TemplateComponentsData.Add(pair.Key, pair.Value);
}
}
但在执行的第一线时,出现以下错误:
找不到引用合同'ServiceReference.GetTemplateParamSoap在ServiceModel客户端配置节的默认终结点元素。这可能是因为没有配置文件,发现你的应用程序,或者是因为匹配这份合同没有终结点元素可以在客户端的元素被发现。
我是什么失踪?
2)我面迁移的asp.net凸出,并从一个域到另一个一起ASMX。
有什么办法相对引用此WebService?
2) I plane to migrate the asp.net proj and asmx together from one domain to another. Is there any way to reference this webservice relatively ?
推荐答案
OK,让我尝试重组您的方案以确保我得到它的权利:
OK, let me try to rephrase your scenario to make sure I got it right:
- 您必须托管在某一领域的ASMX Web服务。
- 您有托管从您要使用WCF客户端(SvcUtil工具)消耗此ASMX Web服务相同或不同的域(这并不重要)的ASP.NET应用程序。
第一步是指向ASMX服务的WSDL添加一个服务引用到ASP.NET应用程序:
The first step is to add a Service Reference to the ASP.NET application by pointing to the WSDL of the ASMX service:
这会做两件事情:
- 将一个服务引用添加到您的Web应用程序
-
它会修改你的web.config,包括客户端的端点:
It will modify your web.config and include the client endpoints:
<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>
现在,当你想调用你的应用程序这个服务,你必须选择要使用的端点:
Now when you want to invoke this service from your application you will have to choose the endpoint you want to use:
using (var client = new ServiceReference1.PhoneNotifySoapClient("PhoneNotifySoap"))
{
var result = client.GetVersion();
}
现在只需用您的实际服务名称代替我的code片段。
Now simply replace my code snippets with your actual service names.
这篇关于调用ASMX从C#服务器端:匹配这份合同终结点元素可以在客户端元素中找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!