2017-02-15 5 views
0

ストリームにイメージを置くことができるWCFサービスを作りたいと思います。WCFサービスストリーミングイメージ

私は設定で次があります。

<service name="Images" behaviorConfiguration="ImagesBehavior"> 
    <endpoint address="http://localhost:5523/Images.svc" 
     binding="basicHttpBinding" contract="Images" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:5523/Images" /> 
     </baseAddresses> 
    </host> 
</service> 

<behavior name="ImagesBehavior"> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <serviceMetadata httpGetEnabled="true" /> 
</behavior> 

とコード:

[OperationContract] 
[WebGet(UriTemplate = "GetImage/{imageID}", 
    BodyStyle = WebMessageBodyStyle.Bare)] 
public Stream GetImage(string imageID) 
{ 
    try 
    { 

     if (WebOperationContext.Current != null) 
      WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; 

     var ms = new MemoryStream(myImage); 
     return ms; 
    } 
    catch (Exception e) 
    { 
if (WebOperationContext.Current != null) 
      WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"; 
     Console.WriteLine("GetImage ERROR:" + e.Message + "\r\n" + e.StackTrace); 
     byte[] errorBytes = Encoding.UTF8.GetBytes("ERROR"); 
     return new MemoryStream(errorBytes); 
    } 
} 

しかし、私は

を持って

http://localhost:5523/Images.svc/GetImage/imagecodeblabla 

のようなブラウザを介してこれをしようとしています

400不正な要求

、いつ何が悪い

を許可されていません

http://localhost:5523/Images/GetImage/imagecodeblabla

405の方法?

+0

WebOperationContext.Currentがnullの場合、間違いなく奇妙な応答が得られます。 – BugFinder

+0

しかし私は機能しなくなった。ブレークポイントに達していません。 – Ksice

答えて

0

サービスSOAPまたはRESTですか? REST構文(WebGetAttribute)を使用しているようですが、バインディングはBasicHttpBinding(SOAP)です。

代わりにWebHttpBindingを試してみてください。