2010-09-10 107 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是一个双/双向绑定(这我假设你想使用基于客户端类的名字),你可能还需要设置其他的东西,如回调合同界面和回调地址 - 但该代码应该至少让你开始,我希望!