如何将字节数组传输到WCF服务 [英] How to transfer the byte array to WCF service

查看:58
本文介绍了如何将字节数组传输到WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试将excel文件转换为字节数组并将其传递给WCF服务方法。

我收到以下异常。请帮我解决这个问题。



这是下面的代码块,我收到错误和

SaveData(*** )方法是调用WCF服务的方法



Hi,

I'm trying to convert an excel file to byte array and passing the same to WCF service method.
I'm getting the following exception. Please help me to resolve this issue.

This is the below code chunk where I'm getting error and
SaveData(***) method is the one which calls the WCF service

string strFile = ViewState[GlobalConstants.strVsfilePath].ToString();
                    DataTable dtSaveData = new DataTable();
                    dtSaveData = (DataTable)ViewState[GlobalConstants.strVsOrginal];
                    DataSet dsSaveData = new DataSet();
                    dsSaveData.DataSetName = "dsfff";
                    dsSaveData.Tables.Add(dtSaveData);
                    dsSaveData.Tables[0].TableName = "dtfff";
                    string strResult = string.Empty;
                    MemoryStream stream = new MemoryStream();
                    dtSaveData.WriteXml(stream, true);
                    stream.Seek(0, SeekOrigin.Begin);
                    StreamReader sr = new StreamReader(stream);
                    string strInputXML = sr.ReadToEnd();
                    string strModifiedXml = strInputXML.Replace("+05:30", "");
                    byte[] btData = FileToByteArray(strFile);
                    File.Delete(strFile);
                    //cByteTransfer objByteTransfer = new cByteTransfer();
                    //objByteTransfer.BTransfer = btData;
                    Stream streamData = new MemoryStream(btData);

                    adminsvc.SaveData(strModifiedXml, dsSaveData.DataSetName, dsSaveData.Tables[0].TableName, strType, strLoginName, "FIXED", btData, (string)ViewState["strWorkbookName"], (string)ViewState["SheetName"]);





异常详细信息





Exception Detail

{System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at ImportExchangeRates.AdminService.IAdminservice.SaveData(String strModifiedXml, String strDatasetName, String strDataTableName, String strModelName, String strLoginName, String strTableType, Byte[] bytWorkbook, String strWorkbookName, String strOuptuSheet)
   at ImportExchangeRates.AdminService.AdminserviceClient.SaveData(String strModifiedXml, String strDatasetName, String strDataTableName, String strModelName, String strLoginName, String strTableType, Byte[] bytWorkbook, String strWorkbookName, String strOuptuSheet)

推荐答案

我在basichttpbinding - >绑定标签中设置了maxStringContentLength =65536000并且它有效。



并且还添加了basichttpbinding下使用的绑定名称 - >这里绑定到端点标签作为属性binding =basicBinding



请查看使用的配置如下所示



I have set the maxStringContentLength="65536000" in basichttpbinding-->binding tag and it worked.

And also added the name of the binding used under basichttpbinding-->binding here into the endpoint tag as an attribute binding="basicBinding"

Please find the configuration used as below

<system.serviceModel>
    <bindings>

      <basicHttpBinding>
       
        <binding name="basicBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="65536000"

          maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        </binding>
        </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="MY_SERVICE.cMY_Module"

             behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="http://localhost:1111/MY_Service.svc" binding="basicBinding"

             contract="MY_SERVICE.IMyService" bindingConfiguration="basicHttpBinding"/>
        <endpoint contract="IMetadataExchange"

           binding="mexHttpBinding" address="mex"/>
      </service>
    </services>
  </system.serviceModel>



谢谢&安培;此致,

Mathi


Thanks & Regards,
Mathi


这篇关于如何将字节数组传输到WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆