phonegap filetransfer.upload を介して wcf rest サービスにファイルを投稿しようとしています。ファイルをサービスに送信すると、すべてをアップロードできますが、ログには HttpContext がサポートされていないと表示されます。私はasp互換性要件を許可しようとしましたが、役に立たず、webOperationContextと同等のものは見つかりませんでした. 助けていただければ幸いです。関連するコードは次のとおりです
。
[OperationContract]
[WebInvoke(UriTemplate = "putFile",
ResponseFormat = WebMessageFormat.Json,
Method = "POST") ]
bool putFile();
}
実装:
public bool putFile()
{
try
{
var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
String driverId = request.Headers["driverId"];
HttpPostedFile file = HttpContext.Current.Request.Files["file"];
String fileName = file.FileName;
int _driverId = Int32.Parse(driverId);
String fileURI = makeLocalPath(file.ContentType, fileName,driverId);
if (file != null)
{
Entities db = new Entities();
var uri = db.dt_media_uri.Where(p => p.driver_id == _driverId && p.uri_value.Equals(fileName));
using (Stream inputStream = file.InputStream)
{
FileStream fileStream = new FileStream(fileURI, FileMode.Create, FileAccess.Write, FileShare.Read);
if (fileStream == null)
{
try
{
inputStream.CopyTo(fileStream);
}
catch { return false; }
try
{
foreach (var v in uri)
{
v.validated = true;
}
}
catch { EventLog.WriteEntry("Application", "unable to validate uri for driverID: " + driverId); }
try
{
db.SaveChanges();
}
catch { return false; }
}
}
}
return true;
}
catch(Exception e) { EventLog.WriteEntry("Application", "unable process filename\n"+e.ToString()); return false; }
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<connectionStrings>
<add name="Entities" connectionString=*non relevant*"/>
</connectionStrings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true">
</serviceHostingEnvironment>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="NewStandardEndpoint0" />
</webHttpEndpoint>
</standardEndpoints>
<services>
<service name="PullOverWcf.Service1">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="crossDomain" name="REST" contract="PullOverWcf.IService1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="21000000"/>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept, driverID" />
</customHeaders>
</httpProtocol>
<security>
<!--authentication>
<windowsAuthentication enabled="true" />
</authentication-->
</security>
</system.webServer>
</configuration>
これはクライアントからのものです:
options.chunkedMode = false;
options.headers = {
driverId : self.driverId
};
console.log(JSON.stringify(options));
var ft = new FileTransfer();
ft.upload(path, encodeURI(self.serverPath + "/putFile"), fileSuccess,
fileFail, options);