2014-12-17 5 views
0

서비스 참조로 프로젝트에 추가 된 외부 웹 서비스가 있습니다. 웹 서비스에서 제공하는 메서드와 속성으로 충분합니까? 여기 이 모양을 어떻게입니다 : 그와외부 wcf 웹 서비스는 어떻게 호출해야합니까?

//Classes from web service 
HHserviceClient h = new HHserviceClient(); 
HHPostPropertyRequest r = new HHPostPropertyRequest 
    { 
    //Web service properties 
    Amenities = c.Amenities, 
    .... 
    MobileNo = c.MobileNo 
    }; 
    //Method from web service 
h.PostProperty(r); 

문제 것은 내가 혼란 스러워요 그 이유는, HHserviceClient이 호출 할 때 예외가 발생 NullReference이다 - 나는 몇 가지 추가 작업을 할 HttpClient를 같은 모든 .NET 클래스를 호출해야합니다. 필자는 외부 wcf 웹 서비스로 어떤 일을하기도 전에 한 번도 본 적이 없었습니다. 그래서 나는 완전히 새롭고 조언을 구했습니다.

업데이트.

 var rq = new HHPostPropertyRequest 
        { 
         Amenities = c.Amenities, 
         Area = c.Area, 
         BathRooms = c.BathRooms, 
         Bedrooms = c.Bedrooms, 
         City = c.City, 
         Company = c.Company, 
         Contact = c.Contact, 
         Country = c.Country, 
         CustomerID = 1000, 
         Description = c.Description, 
         Email = c.Email, 
         LandLineNo = c.LandLineNo, 
         Lattitude = c.Lattitude, 
         Location = c.Location, 
         Longitude = c.Longitude, 
         MobileNo = c.MobileNo 
        }; 
       BasicHttpBinding myBinding = new BasicHttpBinding(); 
       EndpointAddress myEndpoint = new EndpointAddress("http://198.38.94.85/hhsvc/hhservice.svc/postproperty"); 
       ChannelFactory<IHHservice> myChannelFactory = new ChannelFactory<IHHservice>(myBinding, myEndpoint); 
       IHHservice HHservice = myChannelFactory.CreateChannel(); 
       var result = HHservice.PostProperty(rq); 
       ((IClientChannel)HHservice).Close(); 
       myChannelFactory.Close(); 
+1

문제가 있습니까? Visual Studio –

+0

을 통해 서비스 참조를 추가하면 일반적으로 이미 모든 것을 갖게됩니다. 그래서 혼란 스럽습니다. HHserviceClient가 호출 될 때 null 참조 예외가 throw됩니다. –

+0

예외 스택 추적을 표시 할 수 있습니까? Property 객체에 모든 속성에 대한 setter \ getters가 있습니까? –

답변

1

채널 팩토리를 사용하여 접근 할 수 있습니까? 생성 된 구성 등을 사용하지 않습니다.

  var r = new Object() 
      //define binding 
      //assume your binding using basicHttp, change it if you are using something else 
      BasicHttpBinding myBinding = new BasicHttpBinding();   

      //define endpoint url    
      EndpointAddress myEndpoint = new EndpointAddress("http://localhost:11234/HHservice.svc"); //change to real endpoint 

      //Use channle factory instead of generated one 
      ChannelFactory<IHHservice> myChannelFactory = new ChannelFactory<IHHservice>(myBinding, myEndpoint); //Change to you WCF interface 
      IHHservice HHservice= myChannelFactory.CreateChannel(); 

      //and call it    
      var result = HHservice.PostProperty(r); //input to your method 

      ((IClientChannel)HHservice).Close(); 
      myChannelFactory.Close(); 
+0

의 이름이 포함되어 있습니다. 이 오류가 나타납니다. [시스템.InvalidOperationException] = { "ServiceModel 클라이언트 구성 섹션에서 'ServiceReference_HomeHunt.IHHservice'계약을 참조하는 기본 끝점 요소를 찾을 수 없습니다. 응용 프로그램에 대한 구성 파일이 없거나 끝 점이 없기 때문일 수 있습니다. –

+0

이것은입니다. 이 오류는 WCF가 web.config (ABC 주소, 바인딩, 계약)의 끝점에 대한 정의를 찾을 수 없다는 것을 의미합니다.이 오류를 코드로 제외합니다. 그러나 런타임에 ABC를 정의하기 때문에 ChannelFactory가 아닙니다. – polacekpavel

+0

업데이트를 참조하십시오. 이제 return 500 오류가 발생했습니다. –