Webservice 无法使用动态 URL 进行类型转换:XML 文档中存在错误 (2, 691) [英] Webservice fails to cast type using dynamic URL: There is an error in XML document (2, 691)

查看:31
本文介绍了Webservice 无法使用动态 URL 进行类型转换:XML 文档中存在错误 (2, 691)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 app.config 来区分远程 Web 应用程序的预览"和生产"Web 服务 URL.WSDL 在预览版和生产版中是相同的.但是,当我使用的 URL 与 Visual Studio 在 Web References 文件夹中的 URL 不同时,我收到以下错误:XML 文档中存在错误 (2, 691).

I am using the app.config to differentiate "preview" vs "production" web service URLs to a remote web app. The WSDL is the same in both preview and production. But when I use a different URL than the one that Visual Studio has in the Web References folder, I get the following error: There is an error in XML document (2, 691).

以下是我如何设置代码以使用应用设置中定义的 URL 的示例:

Here is an example of how I set my code up to use the URL defined in the app settings:

MyNamespace.MyType.MyService ws = new MyNamespace.MyType.MyService()
{
    Url = System.Configuration.ConfigurationManager.AppSettings["url"]
};

我在两个 WSDL 之间做了一个差异,唯一的区别是 xsd:schema 上的 targetNamespace 属性和 location 上的属性soap:address 元素.

I did a diff between the two WSDLs and the only difference is the targetNamespace attribute on the xsd:schema and the location attribute on the soap:address element.

我已将 URL 行为设置为动态,并且我知道这是可能的,因为我之前在其他预览/生产应用程序中已经这样做过.

I have URL Behavior set to Dynamic and I know this is possible because I have done it before with other preview/production apps.

推荐答案

问题是预览和生产应用程序托管在两个不同的服务器上.将它们托管在同一台服务器(或至少是 Web 服务)上允许命名空间保持不变,唯一的区别是 URL.

The problem was that preview and production apps were hosted on two separate servers. Hosting them on the same server (or at least the webservice) allows the namespaces to remain the same and the only difference is the URL.

过去的网络服务如下所示:

The webservice used to look like this:

  • 生产 - http://production.example.com/myapp/webservice.aspx
  • 预览 ---- http://preview.example.com/myapp/webservice.aspx
  • Production - http://production.example.com/myapp/webservice.aspx
  • Preview ---- http://preview.example.com/myapp/webservice.aspx

解决方法是像这样托管它:

The fix was to host it like this:

  • 生产 - http://example.com/production/myapp/webservice.aspx
  • 预览 ---- http://example.com/preview/myapp/webservice.aspx
  • Production - http://example.com/production/myapp/webservice.aspx
  • Preview ---- http://example.com/preview/myapp/webservice.aspx

如果这是不可能的,我所知道的唯一其他解决方案是有两个网络参考,一个用于生产,另一个用于预览.缺点是您的命名空间(以及您的类型)会有所不同,并且大部分代码都需要复制.

If this is not possible, the only other solution I know of is to have two web references, one for production and another for preview. The disadvantage is that your namespaces (and in turn, your types) will be different and most code will need to be duplicated.

这篇关于Webservice 无法使用动态 URL 进行类型转换:XML 文档中存在错误 (2, 691)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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