Reputation: 627
I'm trying to implement a WCF client in a VS2005 project. In VS2010 it is all working fine, because I just can add the service reference. For the VS2005 I've builded the .config and the Service1.cs with the svcutil. The two files are added in the project and I also added the service reference as a web reference. Further you find the two files of that were generated.
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SDTRfServerClass.WCFService.WSHttpBinding_IService1" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.0.102:8732/Design_Time_Addresses/Calc/Service1/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="SDTRfServerClass.WCFService.IService1" name="WSHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
This is the app.config which I also tried to change to web.config, but that doesn't make any difference.
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IService1")]
public interface IService1
{
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/Add", ReplyAction = "http://tempuri.org/IService1/AddResponse")]
double Add(double n1, double n2);
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/Substract", ReplyAction = "http://tempuri.org/IService1/SubstractResponse")]
double Substract(double n1, double n2);
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/Multiply", ReplyAction = "http://tempuri.org/IService1/MultiplyResponse")]
double Multiply(double n1, double n2);
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/Divide", ReplyAction = "http://tempuri.org/IService1/DivideResponse")]
double Divide(double n1, double n2);
}
This is a part of the Service1.cs. When I try to call the service with the following code I get the error "Could not find the endpointelement with the name WSHttpBinding_IService1 and contract IService1 in the configuration part of the ServiceMode-client. This can be caused if the configuration of the applicaton is not found or that there was found an endpoint which equalize the name. I've tried to change the name with the full solution name at all places. Does anyone as a solution?
client = new Service1Client("WSHttpBinding_IService1");
double result = client.Add(Double.Parse("2"), Double.Parse("4"));
I also tried to use the plug-in for VS2005 to add service reference which create a .map and a .cs file, but I'm keep getting the same error.
Upvotes: 0
Views: 70
Reputation: 423
I think you have some typo problem or you have wrong namespace because error means that .NET cannot find information about your endpoint.
Try post your complete web.config and I've look at it
Or you can use dynamic channel factory like this and don't worry about linking to your web.config
WSHttpBinding myBinding = new WSHttpBinding();
//define endpoint url (where service is deployed)
EndpointAddress myEndpoint = new EndpointAddress("http://192.168.0.102:8732/Design_Time_Addresses/Calc/Service1/"); //change to real endpoint
//Use channel factory instead of generated one
ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint); //Change to you WCF interface
IService1 myServiceClient = myChannelFactory.CreateChannel();
//and call it
var result = myServiceClient.Add(1,1); //input to your method
//other methods
((IClientChannel)myServiceClient).Close();
myChannelFactory.Close();
Upvotes: 0