.net - 使用 SOAPClient 从 ASP 调用 ASP.NET Web 服务

标签 .net asp.net web-services soap asp-classic

我有一个 ASP.NET 网络服务,其内容如下:

[WebService(Namespace = "http://internalservice.net/messageprocessing")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class ProvisioningService : WebService
{
    [WebMethod]
    public XmlDocument ProcessMessage(XmlDocument message)
    {
        // ... do stuff
    }
}

我使用类似的东西从 ASP 调用 Web 服务:
provWSDL = "http://servername:12011/MessageProcessor.asmx?wsdl"
Set service = CreateObject("MSSOAP.SoapClient30")
service.ClientProperty("ServerHTTPRequest") = True
Call service.MSSoapInit(provWSDL)

xmlMessage = "<request><task>....various xml</task></request>"
result = service.ProcessMessage(xmlMessage)

我遇到的问题是,当 XML 到达 ProcessMessage 方法时,Web 服务管道沿途添加了一个默认命名空间。即,如果我在 ProcessMessage(XmlDocument message) 中设置断点,我会看到:
<request xmlns="http://internalservice.net/messageprocessing">
  <task>....various xml</task> 
</request>

当我在线捕获数据包时,我可以看到 SOAP 工具包发送的 XML 与 .NET WS 客户端发送的 XML 略有不同。 SOAP 工具包发送:
<SOAP-ENV:Envelope 
    xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" 
    xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <ProcessMessage xmlns="http://internalservice.net/messageprocessing">
            <message xmlns:SOAPSDK4="http://internalservice.net/messageprocessing">
                <request>
                    <task>...stuff to do</task>
                </request>
            </message>
        </ProcessMessage>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

虽然 .NET 客户端发送:
<soap:Envelope 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <ProcessMessage xmlns="http://internalservice.net/messageprocessing">
            <message>
                <request xmlns="">
                    <task>...stuff to do</task>
                </request>
            </message>
        </ProcessMessage>
    </soap:Body>
</soap:Envelope>

自从我使用 ASP/SOAP 工具包调用 .NET Web 服务已经很久了,我不记得我用来解决此类问题的所有聪明技巧/SOAP-fu。

有任何想法吗?一种解决方案是建立一个 COM 可调用 .NET 代理,该代理将 XML 作为字符串参数并代表我调用 WS,但这是我希望不做的额外复杂性/工作层。

最佳答案

凯夫,

我找到了解决方案,但它不是微不足道的。

您需要创建 IHeaderHandler 的自定义实现来创建正确的 header 。

这里有一个很好的步骤:

http://msdn.microsoft.com/en-us/library/ms980699.aspx

编辑:我看到了你的更新。很好的解决方法,您可能希望将此链接添加为书签:D

关于.net - 使用 SOAPClient 从 ASP 调用 ASP.NET Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19318/

相关文章:

.net - CvMat 和 Imread 与 IpImage 和 CvLoadImage

asp.net mvc c# 工具提示

asp.net-mvc - 更新 WSDL 引用但 web 配置未在 ASP.net MVC 4 项目中更新

c# - 将 fontawesome 图标添加到 asp.net 按钮

javascript - 为什么我的按钮点击会执行多次?

django - Nginx为Django应用提供静态文件

c# - 如何在超时后取消任务等待

.net - 在 64 位进程中调用 DhcpGetClientInfo 失败

.net - 从 VB.Net 中的二进制文件中提取字符串

asp.net - 基于viewstate在Page_PreRender中创建动态控件导致按钮OnClick事件不起作用