动态Web服务URL问题

时间:2014-09-05 06:07:18

标签: c# sql-server web-services service

我有一个服务,我用它来调用几个Web服务,每个Web服务都有DEV,TST和PRD等价物。目前,我一直在创建Web服务的实例,然后交换URL的某些部分,以便根据需要在环境之间进行更改。

我设法让这个工作得很好但是我最近更改了代码以使用数据库来包含不同环境中相同服务的不同URL,但是URL现在导致调用问题,我得到以下内容错误讯息:

System.Web.Services.Protocols.SoapException: Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/.
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at VRLSAPData.web.vrl.InvoiceList.ZB2B_WS_FUNCTIONS_006_SRV.ZB2bCustomerInvoiceList(ZB2bCustomerInvoiceList ZB2bCustomerInvoiceList1) in c:\Users\pigramm\Testing\VS 2010 Projects\VRLSAPData\VRLSAPData\Web References\web.vrl.InvoiceList\Reference.cs:line 81
   at VRLSAPData.SAPAllInvoices.AllInvoices(String environment, String companyNumber, String customerNumber, String dateFrom, String dateTo) in c:\Users\pigramm\Testing\VS 2010 Projects\VRLSAPData\VRLSAPData\SAPAllInvoices.cs:line 31

我在代码中进行如下调用:

public static web.vrl.InvoiceList.ZB2B_WS_FUNCTIONS_006_SRV ConnectToSapAllInvoicesService(string environment = "tst")
{
        var sapInvoiceListProxy = new web.vrl.InvoiceList.ZB2B_WS_FUNCTIONS_006_SRV();

        sapInvoiceListProxy.AllowAutoRedirect = true;
        sapInvoiceListProxy.Url = GetServiceURL(environment, "AllInvoices");

        sapInvoiceListProxy.Timeout = 900000;
        sapInvoiceListProxy.Credentials = sapLogin;

        return sapInvoiceListProxy;
 }

GetServiceURL()根据传递给它的名称和环境从数据库中获取一个URL,我已经检查过,返回的结果是预期的。

我已经尝试调试代码,但我找不到任何错误,URL似乎是正确的,并且当复制到Web浏览器时按预期工作。有谁知道这里出了什么问题?

1 个答案:

答案 0 :(得分:2)

请检查以下链接

Check this link

从上面的链接中获得提示。可能会有所帮助。

  

问题是您正在将Web服务的URL属性设置为WSDL URL。您需要将Web服务实例的URL设置为Web服务本身的位置,这是WSDL中包含的内容。要查找此URL,请在文本编辑器中打开WSDL文档,然后查找该元素的“location”属性。您可以而且仍然应该在Visual Studio中使用WSDL URL作为图形工具,但在运行时进行区分非常重要。

相关问题