1

WSDLから作成されたWeb参照がありますが、ユーザー名/パスワードを渡さない限り、関数を呼び出すことはできません。XMLツールキットの元のコードは次のとおりです。

Set client = CreateObject("MSSOAP.SOAPClient30")
URL = "http://" & host & "/_common/webservices/Trend?wsdl"

client.mssoapinit (URL)

client.ConnectorProperty("WinHTTPAuthScheme") = 1
client.ConnectorProperty("AuthUser") = user
client.ConnectorProperty("AuthPassword") = passwd

On Error GoTo err
Dim result1() As String

result1 = client.getTrendData(expression, startDate, endDate, 
              limitFromStart, maxRecords

AuthUser / AuthPasswordを新しいコードに追加するにはどうすればよいですか?

新しいコード:

    ALCServer.TrendClient tc = new WindowsFormsApplication1.ALCServer.TrendClient();

    foreach(string s in tc.getTrendData(textBox2.Text, "5/25/2009", "5/28/2009", false, 500))
        textBox1.Text+= s;
4

1 に答える 1

1

Found it: Even if Preauthenticate==True, it doesn't do it. You have to overried the WebRequest:

   protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
        HttpWebRequest request;
        request = (HttpWebRequest)base.GetWebRequest(uri);

        if (PreAuthenticate)
        {
            NetworkCredential networkCredentials =
                Credentials.GetCredential(uri, "Basic");

            if (networkCredentials != null)
            {
                byte[] credentialBuffer = new UTF8Encoding().GetBytes(
                    networkCredentials.UserName + ":" +
                    networkCredentials.Password);
                request.Headers["Authorization"] =
                    "Basic " + Convert.ToBase64String(credentialBuffer);
            }
            else
            {
                throw new ApplicationException("No network credentials");
            }
        }
        return request;
    }

Since it gets created as a partial class, you can keep the stub in a separate file and rebuilding the Reference.cs won't clobber you.

于 2009-06-16T21:22:26.920 に答える