如何将文件从android设备上载到restful wcf服务?
我正在构建一个Android应用程序,我需要上传一张用相机拍摄的照片。我需要将其上传到restful WCF服务。我看了很多教程,但似乎都不太管用。我认为我的问题在于WCF服务。我没有得到任何异常,但我得到了一个错误请求的响应。由于WCF服务目前正在我的本地主机上运行,因此我使用10.0.2.2从android emulator访问它。我可以在本地服务上调用其他服务方法,但此方法失败 爪哇 周转基金 配置文件如何将文件从android设备上载到restful wcf服务?,android,wcf,file-upload,Android,Wcf,File Upload,我正在构建一个Android应用程序,我需要上传一张用相机拍摄的照片。我需要将其上传到restful WCF服务。我看了很多教程,但似乎都不太管用。我认为我的问题在于WCF服务。我没有得到任何异常,但我得到了一个错误请求的响应。由于WCF服务目前正在我的本地主机上运行,因此我使用10.0.2.2从android emulator访问它。我可以在本地服务上调用其他服务方法,但此方法失败 爪哇 周转基金 配置文件 <?xml version="1.0"?> <configurati
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"></customErrors>
</system.web>
<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>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<!--<basicHttpBinding>
<binding name="BasicHttpStreaming" transferMode="Streamed">
</binding>
</basicHttpBinding>-->
<webHttpBinding>
<binding name="WebHttpDtreaming" transferMode="Streamed" >
</binding>
</webHttpBinding>
</bindings>
<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>
<services>
<service behaviorConfiguration="PublishMetadataBehavior" name="SystemDesign.Collaborate.Services.ImageService">
<endpoint address="soap" binding="basicHttpBinding" name="soap" contract="SystemDesign.Collaborate.Services.ImageService"/>
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PublishMetadataBehavior">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我做错了什么?在服务端使用WebHttpBinding原始编程模型是您的选择吗?请参阅博客文章,了解如何实现此功能的详细步骤说明。对于任何遇到此问题的人,正如我刚才所做的那样,我需要更新我的WCF服务的maxReceivedMessageSize。这个问题有助于:
您是否能够从不同的客户端(例如,您在同一解决方案中创建的测试客户端)调用WCF方法?如果不是,那么问题可能在您的服务代码中,或者更可能在您的配置中。再说一遍,可能只是您尝试使用的URI不正确……是的。我使用Fiddler和emulator中的android浏览器调用了同一服务中的另一个方法。两者都起作用了。只是这个特殊的调用在我的android应用程序中不起作用。我认为你至少应该删除getExternalStorageDirectory()背后的komma。你有没有想过这个问题?我现在也有同样的问题。谢谢
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ImageService
{
[WebInvoke(Method = "POST")]
public void UploadInspectionPhoto(Stream t)
{
// I put a breakpoint here but it never gets here
// Do something with the stream
}
}
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"></customErrors>
</system.web>
<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>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<!--<basicHttpBinding>
<binding name="BasicHttpStreaming" transferMode="Streamed">
</binding>
</basicHttpBinding>-->
<webHttpBinding>
<binding name="WebHttpDtreaming" transferMode="Streamed" >
</binding>
</webHttpBinding>
</bindings>
<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>
<services>
<service behaviorConfiguration="PublishMetadataBehavior" name="SystemDesign.Collaborate.Services.ImageService">
<endpoint address="soap" binding="basicHttpBinding" name="soap" contract="SystemDesign.Collaborate.Services.ImageService"/>
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PublishMetadataBehavior">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>