0

過去 2 日間、問題の解決策を見つけるためにかなりの調査を行ってきましたが、役に立ちませんでした。

次のようなWCFサービスを作成しました。

[OperationContract]
void CopyMemberFile(string memberNumber, string fileName, byte[] fileBytes);

そして、page_load イベントから次のようにクライアントから呼び出します。

byte[] filebytes = null;

using (Stream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
{
     filebytes = new byte[fs.Length];
     fs.Read(filebytes, (int)0, (int)fs.Length);
}

client.CopyMemberFile(memberNumber, Path.GetFileName(file), filebytes);

私の構成は次のようになります:

クライアント構成:

<configuration>
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="300" cookieless="UseUri" />
  </authentication>
  <membership>
    <providers>
      <clear />
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider" 
             connectionStringName="ApplicationServices" 
             enablePasswordRetrieval="false" 
             enablePasswordReset="true" 
             requiresQuestionAndAnswer="false" 
             requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" 
             minRequiredPasswordLength="6" 
             minRequiredNonalphanumericCharacters="0" 
             passwordAttemptWindow="10" 
             applicationName="/" />
    </providers>
  </membership>
  <profile>
    <properties>
      <add name="FirstName"/>
      <add name="LastName"/>
      <add name="MemberNumber"/>
      <add name="LastVisit" type="System.DateTime"/>
    </properties>
    <providers>
      <clear />
        <add name="AspNetSqlProfileProvider" 
             type="System.Web.Profile.SqlProfileProvider"
             connectionStringName="ApplicationServices" 
             applicationName="/" />
    </providers>
  </profile>
  <roleManager enabled="false">
    <providers>
      <clear />
        <add name="AspNetSqlRoleProvider" 
             type="System.Web.Security.SqlRoleProvider" 
             connectionStringName="ApplicationServices" 
             applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider"
             type="System.Web.Security.WindowsTokenRoleProvider" 
             applicationName="/" />
    </providers>
  </roleManager>
  <httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" 
         type="System.Web.Script.Services.ScriptHandlerFactory" />
    <add path="Telerik.Web.UI.WebResource.axd" 
         type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
  </httpHandlers>
  <httpRuntime maxRequestLength="1048576"/>
</system.web>
<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="online.members.asp.Services.MembersOnlineSeviceAjaxAspNetAjaxBehavior">
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                             multipleSiteBindingsEnabled="true" />
  <services>
    <service name="online.members.asp.Services.MembersOnlineSeviceAjax">
      <endpoint address="" behaviorConfiguration="online.members.asp.Services.MembersOnlineSeviceAjaxAspNetAjaxBehavior"
                binding="webHttpBinding" 
                contract="online.members.asp.Services.MembersOnlineSeviceAjax" />
    </service>
  </services>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IMembershipApplications" 
                     closeTimeout="00:01:00"
                     openTimeout="00:01:00" 
                     receiveTimeout="00:10:00" 
                     sendTimeout="00:01:00"
                     allowCookies="false" 
                     bypassProxyOnLocal="false" 
                     hostNameComparisonMode="StrongWildcard"
                     maxBufferSize="2147483647" 
                     maxBufferPoolSize="2147483647" 
                     maxReceivedMessageSize="2147483647"
                     messageEncoding="Text" 
                     textEncoding="utf-8" 
                     transferMode="Buffered"
                     useDefaultWebProxy="true">
        <readerQuotas maxDepth="128" 
                      maxStringContentLength="2147483647" 
                      maxArrayLength="2147483647"
                      maxBytesPerRead="2147483647" 
                      maxNameTableCharCount="2147483647" />
        <security mode="None">
          <transport clientCredentialType="None" 
                     proxyCredentialType="None"
                     realm="" />
          <message clientCredentialType="UserName" 
                   algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:58119/MembershipApplications.svc"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IMembershipApplications"
              contract="MembershipApplicationsServiceReference.IMembershipApplications"
              name="BasicHttpBinding_IMembershipApplications" />
  </client>
</system.serviceModel>

サービス構成:

<configuration>
  <system.web>
    <roleManager enabled="true" />
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

私が得ているエラーはこれです:

3/02/2013 11:12:39 AM: Upload.aspx Error: The remote server returned an unexpect
ed response: (400) Bad Request.
Server stack trace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResp
onse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factor
y, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeS
pan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message messag
e, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
   at online.members.asp.MembershipApplicationsServiceReference.IMembershipAppli
cations.CopyMemberFile(String memberNumber, String fileName, Byte[] fileBytes)`

それぞれ数KBのファイルをアップロードできますが、8KBを超えると失敗します

どんな助けでも素晴らしいでしょう。

呼び出しコード:

protected void Page_Load(object sender, EventArgs e)
{
    var file = Request.Form["name"];            
    var memberNumber = Request.Form["memberNumber"];
    var tempId = Guid.NewGuid();

    var client = new MembershipApplicationsServiceReference.MembershipApplicationsClient();

    client.LogEvent("Entered Upload.aspx");

    try
    {
        byte[] filebytes = null;

        using (Stream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
        {
            filebytes = new byte[fs.Length];
            fs.Read(filebytes, (int)0, (int)fs.Length);

            client.LogEvent("Starting service call from Upload.aspx");
            client.CopyMemberFile(memberNumber, Path.GetFileName(file), filebytes);                    
        }

        client.LogEvent("Completed service call from Upload.aspx");
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.StackTrace);

        client.LogEvent("Upload.aspx Error: " + ex.Message + ex.StackTrace);

        StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
    }
    finally
    {
        client.LogEvent("Finishing up");
    }
}
4

1 に答える 1

0

サービスの構成ファイルを見ると、.NET 4.0 を使用しており、バインディングを指定していないため、.NET の既定の設定を受け取ることになりますbasicHttpBinding。上記のコメントで提案されているように、サービスの構成ファイルを次のように更新します。

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IMembershipApplications" 
                     closeTimeout="00:01:00"
                     openTimeout="00:01:00" 
                     receiveTimeout="00:10:00" 
                     sendTimeout="00:01:00"
                     allowCookies="false" 
                     bypassProxyOnLocal="false" 
                     hostNameComparisonMode="StrongWildcard"
                     maxBufferSize="2147483647" 
                     maxBufferPoolSize="2147483647" 
                     maxReceivedMessageSize="2147483647"
                     messageEncoding="Text" 
                     textEncoding="utf-8" 
                     transferMode="Buffered"
                     useDefaultWebProxy="true">
        <readerQuotas maxDepth="128" 
                      maxStringContentLength="2147483647" 
                      maxArrayLength="2147483647"
                      maxBytesPerRead="2147483647" 
                      maxNameTableCharCount="2147483647" />
        <security mode="None">
          <transport clientCredentialType="None" 
                     proxyCredentialType="None"
                     realm="" />
          <message clientCredentialType="UserName" 
                   algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <services>
    <service name="YourServiceName">
      <endpoint address="" 
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IMembershipApplications" 
                contract="YourFullyQualifiedContractName" />
    </service>
  </services>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

これにより、WCFbasicHttpBindingは、.NET の既定値ではなく、ユーザーの設定を使用するようになります。

nameまたは、バインディング定義で属性を省略できます。WCF は、構成ファイルによって処理されるすべてのサービスの既定のバインディングとしてそれを使用します (複数ある場合)。

それでも問題が解決しない場合、または現在別のエラーが発生している場合はお知らせください。

于 2013-02-06T07:05:58.407 に答える