2015-01-05 14 views
0

VS2005 프로젝트에서 WCF 클라이언트를 구현하려고합니다. VS2010에서는 서비스 참조를 추가 할 수 있기 때문에 정상적으로 작동합니다. VS2005의 경우 .config 및 Service1.cs를 svcutil로 빌드했습니다. 두 파일이 프로젝트에 추가되었고 서비스 참조가 웹 참조로 추가되었습니다. 생성 된 두 개의 파일을 찾을 수 있습니다.VS2005의 WCF 클라이언트

<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> 

이것은 app.config이며 web.config로 변경하려고했지만 별 차이가 없습니다.

[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); 
} 

이것은 Service1.cs의 일부입니다. 다음 코드로 서비스를 호출하려고하면 "WSHttpBinding_IService1이라는 이름의 끝점 요소를 찾을 수없고 ServiceMode-client의 구성 부분에서 IService1과 계약합니다.이 경우 응용 프로그램의 구성이 다음과 같은 경우 발생할 수 있습니다. 하지를 찾을 수 없거나 이름을 맞춰야 엔드 포인트가 발견되었다. 나는 모든 장소에서 전체 솔루션의 이름으로 이름을 변경하려고했습니다. 이 솔루션으로 사람을합니까? 나는 또한에 시도

client = new Service1Client("WSHttpBinding_IService1"); 
double result = client.Add(Double.Parse("2"), Double.Parse("4")); 

VS2005의 플러그 인을 사용하여 .map 및 .cs 파일을 만드는 서비스 참조를 추가하지만 동일한 오류가 계속 발생합니다.

+0

어떤 NET의 버전을 사용하고 있습니까? –

답변

0

오류가 .NET이 끝점에 대한 정보를 찾을 수 없기 때문에 오타가 있거나 문제가있는 네임 스페이스가 있다고 생각합니다.

은 전체의 Web.config를 게시 시도하고 나는 모습을했습니다의 IT

또는이 같은 동적 채널 공장을 사용하여 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(); 
+0

Thx! VS2005의 WCF 클라이언트에서 WCF 서버의 기능을 사용하는 좋은 방법입니다! – NiAu