Ela*_*nda 20 c# soap web-services visual-studio-2010
我在srv1上写了一个asmx webSerivce.我在srv2上写了一个asp.net(原文:一个asp.net)项目的bll项目.两者都托管在同一个Web域下
我想从asp.net的bll项目中调用asmx (原文:asp.net(c#)代码).
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);
}
}
Run Code Online (Sandbox Code Playgroud)
但在执行第一行时出现以下错误: 无法在ServiceModel客户端配置部分中找到引用合同"ServiceReference.GetTemplateParamSoap"的默认端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.
我错过了什么?
2)我将asp.net proj和asmx从一个域迁移到另一个域.有没有办法相对引用这个webservice?
Dar*_*rov 40
好吧,让我试着改写你的场景,以确保我做对了:
第一步是通过指向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>
Run Code Online (Sandbox Code Playgroud)现在,当您想从应用程序调用此服务时,您必须选择要使用的端点:
using (var client = new ServiceReference1.PhoneNotifySoapClient("PhoneNotifySoap"))
{
var result = client.GetVersion();
}
Run Code Online (Sandbox Code Playgroud)
现在只需用我的实际服务名称替换我的代码片段.
归档时间: |
|
查看次数: |
60271 次 |
最近记录: |