post メソッドを使用してレスト サービスを呼び出すことができず、エンドポイントが見つからないというエラーが発生し続けます。以下のコード:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(
Method = "POST",
UriTemplate = "GetData",
BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json
)]
string GetData(string value);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Service1 : IService1
{
public string GetData(string value)
{
return value;
}
}
web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxUrlLength="1048576" relaxedUrlToFileSystemMapping="true" />
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" />
</protocolMapping>
<services>
<service name="RestPost.Service1" behaviorConfiguration="default">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="RestPost.IService1" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web" >
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="default">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<!-- default binding configration used for all REST services -->
<webHttpBinding>
<!-- max allowed message size incresed to 500 000 Bytes -->
<binding maxBufferSize="95000000" maxReceivedMessageSize="95000000" />
</webHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxUrl="40960000" maxQueryString="20480000" maxAllowedContentLength="20480000" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
これは、ブラウザでURLを呼び出す方法です
http://localhost:57395/Service1.svc/getdata/large base64encoded string here
これは私がフィドラーでそれを呼び出す方法です
これを Casini で実行しようとしています。最終的には IIS 7.5 に展開されます。
base64 でエンコードされた大きな文字列を渡す理由が気になる場合は、JSON 形式でリクエストを送信する必要があるため、そうしています。JSON には IIS がすぐに拒否する特殊な文字があるため、URLencode を使用してみました。これに関する問題は、1000 文字程度を超えることができないことです。長さには有限の制限があります。Base64 エンコーディングと post の使用が唯一の方法でした。そのため、このコードを使用しています。
この Rest サービスの当初の目標は、このサービスに JSON を投稿し、その代わりに JSON 応答を取得する JavaScript ベースのクライアントを提供できるようにすることです。xml 文字列パディングのない純粋な JSON 応答。
残りのサービスへの投稿を機能させるには、助けが必要です。