我一直在搜索這個問題,但仍然無法找到確切的解決方案。對於請求在操作UploadPhotoStream是一個流操作必須有一個參數的類型是流
代碼:
namespace StackSample.Logic
{
[ServiceHeaderBehavior]
[MerchantHeaderBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Merchant : Interfaces.IMerchant
{
public bool UploadPhotoStream(string productid, string photoid, Stream fileData)
{
Logic.Components.Product ca = new Logic.Components.Product();
return ca.UploadPhotoStream(Common.UserValues().Merchant, productid, photoid, fileData);
}
}
}
namespace StackSample.Interfaces
{
[ServiceContract]
public interface IMerchant
{
[OperationContract]
[WebInvoke(UriTemplate = "UploadPhotoStream?productid={productid}&photoid={photoid}", Method = "POST")]
bool UploadPhotoStream(string productid, string photoid, Stream fileData);
}
}
配置:
<bindings>
<basicHttpBinding>
<binding name="SOAPSecure">
<security mode="None" />
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2097152" maxBytesPerRead="4096" maxNameTableCharCount="2097152" />
</binding>
<binding name="SOAPSecureTransfer" transferMode="Streamed" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:15:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="RESTSecure">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
<binding name="RESTSecureTransfer" transferMode="Streamed" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:15:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</webHttpBinding>
</bindings>
<!-- behaviors -->
<behaviors>
<endpointBehaviors>
<behavior name="JSON">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="Default" name="StackSample.Logic.Merchant">
<endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="SOAPSecureTransfer" contract="StackSample.Interfaces.IMerchant" />
<endpoint address="rest" behaviorConfiguration="JSON" binding="webHttpBinding" bindingConfiguration="RESTSecureTransfer" contract="StackSample.Interfaces.IMerchant" />
</service>
</services>
當我嘗試運行http://localhost:64039/Merchant/Merchant.svc
它顯示了一個錯誤:
For request in operation UploadPhotoStream to be a stream the operation must have a single parameter whose type is Stream.
我沒有任何想法該怎麼辦。
錯誤信息的哪部分你不明白嗎? – 2013-03-19 09:22:37
@JohnSaunders我不明白爲什麼它不接受多個參數。因爲我看到一個具有這種UriTemplate的項目,它接受包括流在內的多個參數。我只是做了相同的配置和格式,除了我的wcf使用'svc'文件,而我看到的項目使用WCF 4.0 REST模板,它沒有'svc'文件。 – fiberOptics 2013-03-20 01:38:35
你說這兩種項目類型之間沒有區別 - 除了差異。機會是,這種差異說明了行爲上的差異。 – 2013-03-20 01:39:29