从 C# 服务器端调用 asmx:可以在客户端元素中找到与此合同匹配的端点元素 [英] calling asmx from c# server side: endpoint element matching this contract could be found in the client element

查看:72
本文介绍了从 C# 服务器端调用 asmx:可以在客户端元素中找到与此合同匹配的端点元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 srv1 上写了一个 asmx webSerivce.我在srv2上写了一个asp.net的bll项目(原文:一个asp.net)项目.两者都托管在同一个网域下

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#)代码后面)

I want to call the asmx from the bll project of the asp.net (original text: asp.net(c#) code behind).

1) 我添加了一个网络参考,但找不到任何如何真正调用参考服务的教程.

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);
    }
}

但是在执行第一行时出现以下错误:在 ServiceModel 客户端配置部分中找不到引用合同ServiceReference.GetTemplateParamSoap"的默认端点元素.这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.

but get the following error when executing the first line: Could not find default endpoint element that references contract 'ServiceReference.GetTemplateParamSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

我错过了什么?

2) 我打算将 asp.net proj 和 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, let me try to rephrase your scenario to make sure I got it right:

  1. 您在某个域上托管了 ASMX 网络服务.
  2. 您有一个 ASP.NET 应用程序托管在相同或不同的域(这并不重要),您希望使用 WCF 客户端 (svcutil) 从中使用此 ASMX Web 服务.

第一步是通过指向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 应用程序添加一个 ServiceReference

  • 它将修改您的 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();
}

现在只需将我的代码片段替换为您的实际服务名称.

Now simply replace my code snippets with your actual service names.

这篇关于从 C# 服务器端调用 asmx:可以在客户端元素中找到与此合同匹配的端点元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆