1

我有一个供应商告诉我 SOAP 标头中不应包含 https,但我们仍然可以通过 SSL 进行通信。我们担心的是我们想通过 SSL 进行通信,并且他们的示例代码导致它不会发生。

在他们的示例程序中,他们提供了以下代码:

    if (valservice.Url.StartsWith("https"))
    {
        valservice.Destination = new Microsoft.Web.Services3.Addressing.EndpointReference(
            new Uri(valservice.Url.Replace("https:", "http:")));
    } 

从将其分解为更小的步骤并添加一些调试,似乎当您更改目标时,URL 会自动更改。

if (valservice.Url.StartsWith("https"))
{
    // fix the endpoint just in case (usually not necessary)
    //original code is just this next line 
    //valservice.Destination = new Microsoft.Web.Services3.Addressing.EndpointReference(
    //    new Uri(valservice.Url.Replace("https:", "http:")));


    //test code 
    string holdOriginalURL = valservice.Url;

    Response.WriteLine("1 URL=" + valservice.Url);
    Response.WriteLine("1 Destination=" + valservice.Destination);
    Response.WriteLine("1 Destination.Address.Value=" + valservice.Destination.Address.Value);
    Response.WriteLine("1 Destination.TransportAddress=" + valservice.Destination.TransportAddress);

    //test 
    string newURL = valservice.Url;
    newURL = newURL.Replace("https:", "http:"); 
    //valservice.Destination = new Microsoft.Web.Services3.Addressing.EndpointReference(
    //    new Uri(newURL));
    Microsoft.Web.Services3.Addressing.EndpointReference tempEndPoint = new Uri(newURL);
    valservice.Destination = tempEndPoint; 
    //valservice.Url = holdOriginalURL; 
    Response.WriteLine("2 URL=" + valservice.Url);
    Response.WriteLine("2 Destination=" + valservice.Destination);
    Response.WriteLine("2 Destination.Address.Value =" + valservice.Destination.Address.Value);
    Response.WriteLine("2 Destination.TransportAddress=" + valservice.Destination.TransportAddress);
}

输出:

1 URL=https://someaddress.net/orgid/SomeApplication/SomeService.asmx
1 Destination.Address.Value=https://someaddress.net/orgid/SomeApplication/SomeService.asmx
1 Destination.TransportAddress=https://someaddress.net/orgid/SomeApplication/SomeService.asmx

2 URL=http://someaddress.net/orgid/SomeApplication/SomeService.asmx
2 Destination.Address.Value=http://someaddress.net/orgid/SomeApplication/SomeService.asmx
2 Destination.TransportAddress=http://someaddress.net/orgid/SomeApplication/SomeService.asmx

问题: 目标中的 URL 是否可以与 URL 不同?如果有怎么办?

此外,如果我在更新目标后重置 URL,目标也会更改。似乎两者以某种方式相互联系并且不能不同?

谢谢,

尼尔·沃尔特斯

更新 1:一些研究表明供应商可能能够将SoapActor 属性添加到他们的站点。

当我们在 URL 中有 https 时,他们会给出这个错误:

标头必须与 Web 服务的参与者 URI 值匹配。可以使用 ASMX 类上的 SoapActorAttribute 显式指定参与者 URI 值。在没有该属性的情况下,假定参与者 URI 等于传入消息的 HTTP 请求 URL。收到的标头包含“ https://somesite.net/orgid/SomeApp/SomeService.asmx ”,而接收者期待“ http://somesite.net/orgid/SomeApp/SomeService.asmx ”。

4

1 回答 1

0

供应商的样本确实是错误的,并且没有使用 SSL。解决方案是将“VIA”参数添加到端点的构造函数中:

 valservice.Destination =
            new Microsoft.Web.Services3.Addressing.EndpointReference(
                new Uri(valservice.Url.Replace("https:", "http:")), 
                new Uri(valservice.Url));

http://msdn.microsoft.com/en-us/library/microsoft.web.services3.addressing.endpointreference.via.aspx

于 2010-01-14T23:10:25.363 回答