2010-09-10 121 views
1

我正在使用對web服務的服務引用並創建了它的新實例。我創建了一個消息,並試圖發送此對web服務,但我得到這個錯誤:WCF找不到默認端點

Could not find default endpoint element that references contract 'receivePortService.ITwoWayAsyncVoid' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

現在我部署該應用程序到SharePoint,所以我只是有dll文件。有沒有辦法我可以手動設置代碼中的配置文件的屬性?

receivePortService.TwoWayAsyncVoidClient client = new TaskCompletedHandler.receivePortService.TwoWayAsyncVoidClient(); 
Message msg = Message.CreateMessage(MessageVersion.Default,"*",XmlTextReader.Create(xmlMessage)); 
client.BizTalkSubmit(msg); 

如何設置endpointaddress和沒有app.config的東西?

回答

0

通常,您的TwoWayAsyncVoidClient類應該有幾個重載的構造函數 - 特別應該以BindingEndpointAddress作爲其參數。

因此,在代碼中,您可以創建例如

WSDualHttpBinding myBinding = new WSDualHttpBinding(); 
EndpointAddress epa = new EndpointAddress(new Uri("http://yourserver:7777/YourService/TheService.svc")); 

receivePortService.TwoWayAsyncVoidClient client = new TaskCompletedHandler.receivePortService.TwoWayAsyncVoidClient(myBinding, epa); 

隨着WSDualHttpBinding是一個雙/雙向綁定(這我假設你想使用基於客戶端類的名字),你可能還需要設置其他的東西,如回調合同界面和回調地址 - 但該代碼應該至少讓你開始,我希望!

相關問題