好吧,它已經有一段時間,因爲我已經有一個Web引用工作。我需要一個進修。我想我有我需要得到迴應,但要我失去了一些東西代碼的約80%。也許你可以幫我:)需要一些幫助的代碼用於獲取從Web服務的響應。你能幫我連接點嗎?
考慮:
指向.wsdl
URL時,在方法列表稱爲GetSomething
一個Web方法。
這將產生幾類/對象:
GetSomethingRequest
GetSomethingCompletedEventHandler
GetSomethingCompletedEventArgs
myComplexType
其中我用它來創建此代碼:
void someMethodToTestResponse()
{
GetSomethingRequest request = new GetSomethingRequest();
// fill in the request
request.myComplexType.Property1 = "Blah";
request.myComplexType.Property2 = "Kachoo";
GetSomethingCompletedEventHandler handler = GetSomethingCompleted_Response;
//.... ok now what?
//handler.Invoke(???)
// at this point I'm supposed to send an object for source (request maybe?)
// and a new instance of GetSomethingCompletedEventArgs but that class is
// asking for stuff that makes me think that is not the right idea.
}
void GetSomethingCompleted_Response(object source, GetSomethingCompletedEventArgs args)
{
// get the result
var result = args.Result;
}
我在做什麼錯?我錯過了什麼?提前致謝。
.NET哪個版本您使用的?除非你被困在.NET 2.0中,否則你應該使用服務引用。 – 2011-02-24 19:57:36
好問題,我正在使用3.5。 – DJTripleThreat 2011-02-24 19:59:18
然後請參閱https://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/ – 2011-02-24 20:44:15