簡體   English   中英

PERL WCF Web服務調用失敗

[英]PERL WCF Web Service Call Fails

我正在使用PERL向我們的供應商提供的Web服務之一進行Web服務調用。 Web服務使用SOAP 1.2和WSHttpBinding。

我可以成功調用Web服務中的大多數呼叫,但RetrieveReport呼叫除外。 RetrieveReport調用應該流式傳輸文件。 但是,我得到下面的答復。

使用C#代碼提供了一個調用RetrieveReport的示例,其中提到使用以下綁定。 但是我不知道如何在PERL中執行此操作。 如果有人可以提供任何幫助,我先謝謝您。

C#應用程序配置綁定

<binding name="WSHttpBinding_IBIStreamService" closeTimeout="00:02:00"
                    openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                    </security>
                </binding>

PERL代碼

my $reportKey = 'report_key';
my $reportUri = 'report_uri';

my $xml = new XML::Simple;
my $userAgent = LWP::UserAgent->new(agent => 'https://service.com/services/BIDataService');

my $message = <<'.';
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
  <a:Action s:mustUnderstand="1">http://service.com/dataservices/bistream/2/IBIStreamService/RetrieveReport</a:Action> 
  <h:ReportKey xmlns:h="http://service.com/dataservices/bistream/2" xmlns="http://service.com/dataservices/bistream/2">[ReportKey]</h:ReportKey>
  <a:To s:mustUnderstand="1">[ReportRetrievalUri]</a:To> 
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <RetrieveReportRequest xmlns="http://service.com/dataservices/bistream/2" /> 
  </s:Body>
  </s:Envelope>
.

# Replace the dynamic values
$message =~ s/\[ReportKey\]/$reportKey/g;
$message =~ s/\[ReportRetrievalUri\]/$reportUri/g;

my $request = HTTP::Request->new(POST => $uri);

$request->header(SOAPAction => '"http://service.com/dataservices/bistream/2/IBIStreamService/RetrieveReport"');
$request->content($message);
$request->content_type("application/soap+xml; charset=utf-8");

print "-- CONTENT --\n\n";
print $request->content . "\n\n";

my $response = $userAgent->request($request);

if ($response->is_success) {
    print "--SUCCESS--\n" . $response->decoded_content . "\n";
} else {
    print "--FAILURE--\n" . $response->status_line, "\n";
    print $response->error_as_HTML;
}

供應商的回應

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/fault</a:Action>
    </s:Header>
    <s:Body>
        <s:Fault>
            <s:Code>
                <s:Value>s:Sender</s:Value>
                <s:Subcode>
                    <s:Value>a:ActionNotSupported</s:Value>
                </s:Subcode>
            </s:Code>
            <s:Reason>
                <s:Text xml:lang="en-US">The message with Action \'http://service.com/dataservices/bistream/2/IBIStreamService/RetrieveReport\' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</s:Text>
            </s:Reason>
        </s:Fault>
    </s:Body>
</s:Envelope>

WSDL來源

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="BIStreamService" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:i0="http://service.com/dataservices/bistream/2" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
    <wsp:Policy wsu:Id="WSHttpBinding_IBIStreamService_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <wsaw:UsingAddressing/>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsdl:import namespace="http://service.com/dataservices/bistream/2" location="https://service.com/services/BIStreamingService?wsdl=wsdl0"/>
    <wsdl:types/>
    <wsdl:binding name="WSHttpBinding_IBIStreamService" type="i0:IBIStreamService">
        <wsp:PolicyReference URI="#WSHttpBinding_IBIStreamService_policy"/>
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="RetrieveReport">
            <soap12:operation soapAction="http://service.com/dataservices/bistream/2/IBIStreamService/RetrieveReport" style="document"/>
            <wsdl:input name="RetrieveReportRequest">
                <soap12:header message="i0:RetrieveReportRequest_Headers" part="ReportKey" use="literal"/>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="StreamReportResponse">
                <soap12:header message="i0:StreamReportResponse_Headers" part="Status" use="literal"/>
                <soap12:header message="i0:StreamReportResponse_Headers" part="StatusMessage" use="literal"/>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="BasicHttpBinding_IBIStreamService" type="i0:IBIStreamService">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="RetrieveReport">
            <soap:operation soapAction="http://service.com/dataservices/bistream/2/IBIStreamService/RetrieveReport" style="document"/>
            <wsdl:input name="RetrieveReportRequest">
                <soap:header message="i0:RetrieveReportRequest_Headers" part="ReportKey" use="literal"/>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="StreamReportResponse">
                <soap:header message="i0:StreamReportResponse_Headers" part="Status" use="literal"/>
                <soap:header message="i0:StreamReportResponse_Headers" part="StatusMessage" use="literal"/>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="BIStreamService">
        <wsdl:port name="WSHttpBinding_IBIStreamService" binding="tns:WSHttpBinding_IBIStreamService">
            <soap12:address location="https://service.com/services/BIStreamingService"/>
            <wsa10:EndpointReference>
                <wsa10:Address>https://service.com/services/BIStreamingService</wsa10:Address>
            </wsa10:EndpointReference>
        </wsdl:port>
        <wsdl:port name="BasicHttpBinding_IBIStreamService" binding="tns:BasicHttpBinding_IBIStreamService">
            <soap:address location="https://service.com/services/BIStreamingService"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

我發現了問題。

報告Web服務有兩個URL。 一個執行報告,另一個執行以檢索報告。 我將LWP :: UserAgent-> new(agent =>'')和HTTP :: Request-> new(POST =>'')修改為在檢索時都指向https://service.com/services/BIStreamingService報告,現在可以使用了。

謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM