文件传输到WCF服务接收405
我正在使用PhoneGap开发一个移动应用程序,其中一个功能涉及将图像上传到web服务进行处理。我已经编写了一个托管在IIS中的WCF服务来接受映像,其契约如下所示:文件传输到WCF服务接收405,wcf,rest,cordova,Wcf,Rest,Cordova,我正在使用PhoneGap开发一个移动应用程序,其中一个功能涉及将图像上传到web服务进行处理。我已经编写了一个托管在IIS中的WCF服务来接受映像,其契约如下所示: [ServiceContract] public interface IImages { [OperationContract(Name="UploadImage")] [WebInvoke(UriTemplate = "?file_key={fileKey}", Method = "POST", BodyStyl
[ServiceContract]
public interface IImages
{
[OperationContract(Name="UploadImage")]
[WebInvoke(UriTemplate = "?file_key={fileKey}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
ImageResource UploadImage(string fileKey, Stream imageStream);
}
ft.upload(uri, GetServerUrl()+"images.svc/?file_key="+options.fileKey, ns.UploadImageSuccess, ns.UploadImageError, options);
my web.config中的配置部分如下所示:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<serviceActivations>
<add service="Services.Images" relativeAddress="images.svc" />
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="DefaultServiceBehavior" name="Services.Images">
<endpoint behaviorConfiguration="DefaultEndpointBehavior" binding="webHttpBinding" bindingConfiguration="PublicStreamBinding" contract="Services.Contracts.IImages" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="PublicStreamBinding"
maxReceivedMessageSize="2000000000" transferMode="Streamed">
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="DefaultEndpointBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="30" maxConcurrentInstances="30" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
好吧,我想我知道了。显然,当方法像这样托管在根目录下时,如果uri中的服务名称后面没有“/”,请求将无法正确路由。因此,在上载文件的函数中,我将ft.upload行更改为:
[ServiceContract]
public interface IImages
{
[OperationContract(Name="UploadImage")]
[WebInvoke(UriTemplate = "?file_key={fileKey}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
ImageResource UploadImage(string fileKey, Stream imageStream);
}
ft.upload(uri, GetServerUrl()+"images.svc/?file_key="+options.fileKey, ns.UploadImageSuccess, ns.UploadImageError, options);
成功了。你能给我们看一下你上传文件时使用的代码吗?当然,我已经用将文件上传到服务的函数更新了帖子。你使用的ImageResource类是什么?