2012-02-16 6 views
2

RESTプロジェクトが正常に動作REST、これはこのアドレスを介してアクセスすることができます。WCFのSOAPを組み合わせると

http://localhost:8525/Device/Login?deviceID=testid&password=a&serialNum=testserial

私も自分RESTプロジェクトでWCFのSOAPプロジェクトを持って、これら二つのプロジェクトは、異なるフォルダに分離されています、 "SOAP"、 "REST"などがあります。

私の問題は、私はこのコードを入れた後、ということである:

private void RegisterRoutes() 
{ 
    RouteTable.Routes.Add(new ServiceRoute("Device", new WebServiceHostFactory(), typeof(Rest.DeviceComponent)));    
} 

を私は今、私はこのアドレスを使用して前にアクセスすることができましたSOAPサービスにアクセスすることはできません。

http://localhost:8525/DeviceComponent.svc(WCFTestを使用してクライアント)

ここでは、WebConfigの

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <!-- 
      Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
      via the attributes on the <standardEndpoint> element below 
     --> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
    <handlers> 
     <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/> 
    </handlers> 
    </system.webServer> 
</configuration> 
ある

そして、Global.asax.cs

private void RegisterRoutes() 
{ 
    RouteTable.Routes.Add(new ServiceRoute("Device", new WebServiceHostFactory(), typeof(Rest.DeviceComponent))); 
}  

SOAPサンプル契約

namespace TSDEVICE.SoapSVC.Interface 
{ 
    [ServiceContract] 
    public interface IDeviceComponent 
    { 
     [OperationContract] 
     Session Login(string deviceID, string password, string serialNum, string ip); 
     [OperationContract] 
     bool Logout(DeviceSession session); 
     [OperationContract] 
     bool IsLatestVersion(DeviceSession session, int version); 
     [OperationContract] 
     byte[] DownloadLatest(DeviceSession details); 
     [OperationContract] 
     DateTime GetServerTime(DeviceSession session, long branchID); 
     [OperationContract] 
     bool AddDevice(UserSession session, Device deviceitem); 
     [OperationContract] 
     bool RemoveDevice(UserSession session, long deviceID); 
    } 
} 

、残りの部分の内側:

namespace TSDEVICE.Rest 
{ 
    [ServiceContract] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
    public class DeviceComponent 
    { 
     [WebInvoke(UriTemplate = "Login?deviceID={deviceID}&password={password}&serialNum={serialNum}", Method = "POST")] 
     [OperationContract] 
     public TMODELDEVICE.Entities.Session Login(string deviceID, string password, string serialNum) 
     { 
      string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; 
      TMODELDEVICE.Logic.DeviceComponent restDC = new TMODELDEVICE.Logic.DeviceComponent(); 
      return restDC.Login(deviceID, password, serialNum, ip); 
     } 

     public string Sample() 
     { 
      return "Hello"; 
     } 
    } 
} 

私はそれを行うことができますどのように、SOAPやRESTにアクセスする必要が?どうもありがとう!

EDIT

私は.SVCファイル "をスタートページとして設定" しようとすると、私はこのエラーを取得:

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata. 

EDIT 2

今、私が見つけました本当の問題。

web.configのASP.NET互換モードがtrueの場合、SOAPは動作しませんが、RESTはそれを必要とします。これでどうしたらいいですか?ありがとう

+0

RESTプロジェクトでWCF SOAPプロジェクトを使用しているとしたら、1つのソリューションで2つの異なるプロジェクト、または1つのプロジェクトで2つのサービスを意味しますか?また、ルートコレクションと一致するパスからsvcファイルを移動してみてください。それはうまくいくはずです。 – Rajesh

+0

1つのプロジェクトで2つのサービス。 – fiberOptics

答えて

3

私は、RESTとSOAPサービスの両方が公開されているRESTプロジェクトを持っています。今私はいくつかのクライアントによってアクセスされるSOAPサービスの.svcファイルを配置しました。

下のスクリーンショットは私のプロジェクト、Global.asaxの中にルート設定、出力RESTサービスのアクセスと.SVCファイルへのアクセス(SOAPサービス)

sample screenshot

UPDATEのフォルダ構造を与えます: 私のウェブを見つけてください。(私のアプリケーションはIISでホストされている)設定:

web.config

私のクラスを見つけてください、私のインターフェースISampleServiceを実装しています:私は上記のソリューションを鑑賞しながら

class

+0

私たちはほぼ同じようにしているようですが、私のwebconfigに何か不足がありますか? webConfigを表示できますか?ありがとう。私はあなたがしたことを試みます。 – fiberOptics

+0

私の答えはweb.config – Rajesh

+0

のスクリーンショットで更新されました。私はあなたのことに従おうとしましたが、エラーの原因を見つけました。私の編集した質問を参照してください。 – fiberOptics

0

- 見つけ、私がしていますあなたが問題を考えるのを忘れてKISSの原則に従わなければ、管理や配備がはるかに簡単です。

サービス契約:IService.cs

namespace DontTazeMe.Bro 
{ 
    [ServiceContract] 
    public interface IService 
    { 
     [OperationContract] 
     [WebGet] 
     List<GeoMapData> GetToTheChopper(); 
    } 
} 

実装:Service.cs

namespace DontTazeMe.Bro 
{ 
    public class WSDLService : IService 
    { 
     public List<GeoMapData> GetToTheChopper() 
     { 
      return ItsNotEasyBeingChessy.Instance.GetToTheChopperGeoData(); 
     } 
    } 

    public class RESTService : WSDLService 
    { 
     // Let's move along folks, nothing to see here... 
     // Seriously though - there is no need to duplicate the effort made in 
     // the WSDLService class as it can be inherited and by proxy implementing 
     // the appropriate contract 
    } 
} 

設定

<system.serviceModel> 
    <services> 
     <!-- SOAP Service --> 
     <service name="DontTazeMe.Bro.WSDLService"> 
     <endpoint address="" binding="basicHttpBinding" contract="DontTazeMe.Bro.IService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/DontTazeMe.Bro/Service/" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="DontTazeMe.Bro.RESTService"> 
     <endpoint address="" binding="webHttpBinding" contract="DontTazeMe.Bro.IService" behaviorConfiguration="Restful" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/DontTazeMe.Bro/Rest/Service/" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <behaviors> 
     <endpointBehaviors> 
     <behavior name="Restful"> 
      <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped" /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

このメソッドは、設定を取り消すことなく正常に動作します

関連する問題