簡體   English   中英

.NET使用SAP Web服務

[英].NET consume SAP web service

我試圖弄清楚如何使用SAP Web服務。 我有一個.WSDL文件,用於在SAP中查找某些信息。

我的.WSDL文件:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="Customer_Out" targetNamespace="..." xmlns:p1="...." xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:documentation/>
    <wsp:UsingPolicy wsdl:required="true"/>
    <wsp:Policy wsu:Id="OP_CustomerRead_sync"/>
    <wsdl:types>
        <xsd:schema targetNamespace="..." xmlns="..." xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="MT_CustomerRead_response" type="DT_CustomerRead_response"/>
            <xsd:element name="FMT_Customer">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="standard" type="ExchangeFaultData"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="MT_CustomerRead_request" type="DT_CustomerRead_request"/>
            <xsd:complexType name="ExchangeFaultData">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/VersionID">..</xsd:appinfo>
                </xsd:annotation>
                <xsd:sequence>
                    <xsd:element name="faultText" type="xsd:string"/>
                    <xsd:element name="faultUrl" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="faultDetail" type="ExchangeLogData" minOccurs="0" maxOccurs="unbounded"/>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="DT_Customer">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/VersionID">...</xsd:appinfo>
                </xsd:annotation>
                <xsd:sequence>
                    <xsd:element name="BpId" type="xsd:string">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="Name" type="xsd:string">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="AccountGroup" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="Street" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="Number" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="City" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="Country" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="Region" type="xsd:string" minOccurs="0"/>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="DT_CustomerRead_request">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/VersionID">...</xsd:appinfo>
                </xsd:annotation>
                <xsd:sequence>
                    <xsd:element name="RowLimit" type="xsd:integer"/>
                    <xsd:element name="BpId" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="10"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="Name" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="ExternalCustomer" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="AccountGroup" type="xsd:string" minOccurs="0">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="ExchangeLogData">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/VersionID">...</xsd:appinfo>
                </xsd:annotation>
                <xsd:sequence>
                    <xsd:element name="severity" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="text" type="xsd:string"/>
                    <xsd:element name="url" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="id" type="xsd:string" minOccurs="0"/>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="DT_CustomerRead_response">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/VersionID">...</xsd:appinfo>
                </xsd:annotation>
                <xsd:sequence>
                    <xsd:element name="Customer" type="DT_Customer" minOccurs="0" maxOccurs="unbounded">
                        <xsd:annotation>
                            <xsd:appinfo source="http://sap.com/xi/TextID">...</xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element name="Remark" type="xsd:string" minOccurs="0"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="MT_CustomerRead_request">
        <wsdl:documentation/>
        <wsdl:part name="MT_CustomerRead_request" element="p1:MT_CustomerRead_request"/>
    </wsdl:message>
    <wsdl:message name="MT_CustomerRead_response">
        <wsdl:documentation/>
        <wsdl:part name="MT_CustomerRead_response" element="p1:MT_CustomerRead_response"/>
    </wsdl:message>
    <wsdl:message name="FMT_Customer">
        <wsdl:documentation/>
        <wsdl:part name="FMT_Customer" element="p1:FMT_Customer"/>
    </wsdl:message>
    <wsdl:portType name="Customer_Out">
        <wsdl:documentation/>
        <wsdl:operation name="CustomerRead_sync">
            <wsdl:documentation/>
            <wsp:Policy>
                <wsp:PolicyReference URI="#OP_CustomerRead_sync"/>
            </wsp:Policy>
            <wsdl:input message="p1:MT_CustomerRead_request"/>
            <wsdl:output message="p1:MT_CustomerRead_response"/>
            <wsdl:fault name="FMT_Customer" message="p1:FMT_Customer"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="Customer_OutBinding" type="p1:Customer_Out">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
        <wsdl:operation name="CustomerRead_sync">
            <soap:operation soapAction="http://sap.com/xi/WebService/soap1.1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            <wsdl:input>
                <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            </wsdl:output>
            <wsdl:fault name="FMT_Customer">
                <soap:fault use="literal" name="FMT_Customer" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="Customer_OutService">
        <wsdl:port name="HTTP_Port" binding="p1:Customer_OutBinding">
            <soap:address location="..." xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
        </wsdl:port>        
    </wsdl:service>
</wsdl:definitions>

我在.NET項目中添加了一個服務引用,該服務引用了.WSDL文件。 這創建了一個命名空間,該命名空間使我可以創建幾個類的實例(總共9個)。

我似乎找不到如何傳遞請求並接收相應的響應。 我應該解析這些請求/響應嗎? 我知道教程,但它與我正在處理的文件並不完全對應。

請求看起來像這樣:

<man:MT_CustomerRead_request>
         <RowLimit>100</RowLimit>
         <!--Optional:-->
         <!-- <CustomerId>?
         <!--Optional:-->
         <Name>Dell*</Name>
         <!--Optional:-->
         <!--Optional:-->
         <AccountGroup>ABC</AccountGroup>
</man:MT_CustomerRead_request>

提前致謝

我只是在研究這個主題,下面是一個有關如何在.NET(C#)中創建請求和調用SAP服務的示例。

// Create the client
SapServiceReference.ECC_WS sapService = new SapServiceReference.ECC_WS();
sapService.Credentials = new NetworkCredential("Account", "Password");

// Prepare the parameters
SapServiceReference._parameters param = new SapServiceReference._parameters();
param.id = 1;
param.action = "R";

// Call SAP service
SapServiceReference._ws_Response response = sapService._someFunction(param);
string result = response.EvDescriptionText.Tdline;

暫無
暫無

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

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