2013-09-30 4 views
0

WCF 웹 서비스를 만드는 데 초보자입니다. 대상 프레임 워크 4.5 VS2012 사용하고 있습니다. 내 프로젝트에 WCF 서비스 파일을 추가했습니다. 에서 "IService.cs는"나는 다음과 같은 코드 WCF 서비스에 메서드가 없습니다.

namespace _3TWebServ 
    { 
     // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. 
     [ServiceContract] 
     public interface IService1 
     { 
      [OperationContract] 
      [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, 
          RequestFormat = WebMessageFormat.Json, 
          UriTemplate = "Calculate")] 
      String Calculate(Inputs ip1); 
     } 


     [DataContract] 
     public class Inputs 
     { 
      [DataMember(Name = "Coil_type")] 
      public string Coil_type { get; set;} 

      [DataMember(Name = "Finned_length")] 
      public string Finned_length { get; set;} 
     } 

    } 

와 "Service.svc.cs"

namespace _3TWebServ 
{ 
    public class Service1 : IService1 
    { 
     [DataMember] 
     public string input; 

     public String Calculate(Inputs ip1) 
     { 
      String str = ip1.Coil_type + ip1.Finned_length; 
      return str; 
     } 
    } 
} 

그러나 나는 그것이 표시되지 내 서비스를 실행할 때 문제가 온다에서

을 쓴 내 메서드 Calulate, 다음과 같이 URL을 전달할 때 localhost : 2121/Service1.svc/"method not allowed"오류가 표시됩니다.

Google 검색을 수행하고 IIS 관리자 디렉터리 검색을 활성화했습니다. 구성 파일은 다음과 같습니다.

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    </system.web> 

    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="_3TWebServ.IService1" name="_3TWebServ.Service1"> 
     <endpoint address="" behaviorConfiguration="Rest" binding="webHttpBinding" contract="_3TWebServ.IService1"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <!--endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />--> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="_3TWebServ.IService1"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 

     <endpointBehaviors> 
     <behavior name="Rest"> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 

    </behaviors> 
    </system.serviceModel> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <directoryBrowse enabled="true"/> 
    </system.webServer> 

</configuration> 

답변

0

몇 가지 가능한 문제점이 있습니다.

  1. Calculate 메서드는 HTTP POST 요청에 대해 설정됩니다. 적절한 응답을 얻으려면 HTTP POST 요청을 만들어야합니다.
  2. 요청 형식이 JSON (RequestFormat 속성 속성 값)이므로 요청 본문에 JSON 형식의 매개 변수 ({ "Coil_type": "type", "Finned_length": 12})가 포함되어 있는지 확인하십시오.
  3. 서비스 구현에 [DataMember] 공용 문자열 입력이있는 이유는 무엇입니까? 서비스 구현은 일반적으로 운영 계약을 수행해야합니다.
+0

HTTP 게시 요청 방법을 알려주십시오. – Rahul

+0

클라이언트 응용 프로그램에 따라 다릅니다. HttpClient, HttpWebRequest, ajax/javasript, fiddler를 사용하여 POST 요청을 할 수 있습니다. 인터넷에서 자세한 내용을 검색 할 수 있습니다. – Praburaj

관련 문제