WCF uploading Image to server Binding Error
I have problem with WFC server or client config. When I try to upload Image to server I get error:
Content Type multipart/related; type="application/xop+xml";
start="<http://tempuri.org/0>";
boundary="uuid:868d52b2-10f6-4661-8784-bf81f3a84c16+id=1";
start-info="application/soap+xml" was not supported by service http://localhost:8080/PhotoService/. The client and service bindings may be mismatched.
Could someone help me to configure server and client or to tell me where did I get mistake?
I have such configuration:
On client side:
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPhotoService" maxReceivedMessageSize ="2000000" messageEncoding="Mtom" maxBufferPoolSize="2000000">
<readerQuotas maxArrayLength="50000000" maxStringContentLength="2000000"/>
<security mode="None">
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/PhotoService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPhotoService"
contract="PhotoService.IPhotoService" name="WSHttpBinding_IPhotoService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
On Server side:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="PhotoService.PhotoService">
<endpoint address="" binding="wsHttpBinding" contract="PhotoService.IPhotoService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/PhotoService/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttp" maxReceivedMessageSize ="2000000" messageEncoding="Mtom" maxBufferPoolSize="2000000">
<readerQuotas maxArrayLength="50000000" maxStringContentLen开发者_StackOverflowgth="2000000"/>
<security mode="None">
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Client side sources:
private void AddPhoto()
{
try
{
Image image = Image.FromFile(WayToFile);
var obj = new PhotoData();
obj.ID = Guid.NewGuid().ToString();
obj.Image = Photo.ImageToByteArray(image);
obj.Title = _title;
obj.Description = _description;
using (var service = new PhotoServiceClient())
service.InsertPhoto(obj);
AllPhotos.Add(new Photo(obj));
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
public static Image ByteArrayToImage(byte[] byteArrayIn)
{
var ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
public static byte[] ImageToByteArray(Image imageIn)
{
var ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
Server side sources:
[DataContract]
public class PhotoData
{
private string _id;
private string _title;
private string _description;
private byte[] _image;
[DataMember]
public string ID
{
set { _id = value; }
get { return _id; }
}
[DataMember]
public string Title
{
set { _title = value; }
get { return _title; }
}
[DataMember]
public string Description
{
set { _description = value; }
get { return _description; }
}
[DataMember]
public byte[] Image
{
set { _image = value; }
get { return _image; }
}
}
[ServiceContract]
public interface IPhotoService
{
[OperationContract(IsOneWay = true)]
void InsertPhoto(PhotoData photo);
}
It seens like you didn't set binding for server
In your server config add bindingConfiguration="wsHttp"
to line
<endpoint address="" binding="wsHttpBinding" contract="PhotoService.IPhotoService">
精彩评论