4

私は完全なC#初心者であり、これを数時間クラックしようとして成功しませんでした...

C#で使用するSoapClientを構築する必要があります...既存のphpクライアントをc#に移植しようとしています。

基本的に:ユーザーとパスワードを含むSoapヘッダーを使用してリクエストを行う必要があります。これは、送信する必要があるxmlの例です。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://webservices.paymentmanager.mycheck.com">
    <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken>
                <wsse:Username>test</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <SOAP-ENV:Body>
        <ns1:testws>
            <ns1:x>1</ns1:x>
        </ns1:testws>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

VisualStudioの「サービス参照の追加...」を使用しました。

このサービスはうまく機能しており、phpを使用すると見事に機能します。

私が考えたC#:

namespace ConsoleApplication1
{
    class Program
    {
        const String VENDOR_ID = "8723";
        const String VENDOR_PASS = "test";
        const String VENDOR_USER = "pass";
        static void Main(string[] args)
        {
            try
            {
                PaymentManager.PaymentManagerPortTypeClient test = new PaymentManager.PaymentManagerPortTypeClient();
                int num = test.testws(5);
                Console.WriteLine(num);
            }
            catch( Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }

}

明らかに、私はSoapヘッダーを実装する方法を知らなかったので、「Missing SOAPHeaders」例外(WebServiceから受信)をスローします。

4

3 に答える 3

4

私も同じ問題を抱えていました。解決策は見つかりませんでした。最終的には、SOAPメッセージ全体を作成し、HTTPWebRequestを介して送信する必要がありました。

こちらをご覧ください。

于 2012-07-02T13:26:41.063 に答える
0

次に、認証ヘッダーをSOAP Webサービスに送信する方法の例を示します。Webサービスの認証(SOAPヘッダーを使用)

于 2012-06-03T12:38:30.117 に答える
-1
        XmlDocument ReqDoc = new XmlDocument();
        XmlDocument doc = new XmlDocument();
            // request message
        ReqDoc.Load(@"D:\104Resqurst.xml");
           //adding soap headder 
        XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("soapenv", "Envelope", "http://www.w3.org/2001/XMLSchema-instance"));
        root.SetAttribute("xmlns", "http://mark.com/services/contracts");
        XmlElement header = (XmlElement)root.AppendChild(doc.CreateElement("soapenv", "Header", "http://www.w3.org/2001/XMLSchema-instance"));
        XmlElement body = (XmlElement)root.AppendChild(doc.CreateElement("soapenv", "Body", "http://www.w3.org/2001/XMLSchema-instance"));
       //assigning the request document to soap header doc
        doc.GetElementsByTagName("soapenv:Body")[0].InnerXml = ReqDoc.OuterXml;
于 2016-06-10T03:05:46.133 に答える