के माध्यम से कर रही है ग्राहक से नहीं सभी मापदंडों मैं बिल्कुल यकीन है कि पूछने के लिए कि यह कैसे तो मैं एक SSCCEसरल WCF सेवा, सेवा
मैं इस सरल WCF सेवा है नहीं बनाया था
[ServiceContract]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class EmailService
{
[WebInvoke(UriTemplate = "/SendEmail", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Xml)]
public bool SendEmail(EmailData data)
{
try
{
byte[] fileBinaryContents = Convert.FromBase64String(data.Enc64FileContents);
File.WriteAllBytes(data.FileName, fileBinaryContents);
return true;
}
catch (Exception)
{
return false;
}
}
}
[DataContract(Namespace = "http://somenamespace/")]
public class EmailData
{
[DataMember]
public string FileName { get; set; }
[DataMember]
public string EmailAddress { get; set; }
[DataMember]
public string Enc64FileContents { get; set; }
}
और मैं webservice विधि को कॉल करने के लिए Winforms क्लाइंट प्राप्त करने का प्रयास कर रहा हूं; मेरे पास
string URI = " http://localhost:59961/EmailService/SendEmail";
string fileContents = Convert.ToBase64String(File.ReadAllBytes("test.txt"));
EmailData emailData = new EmailData
{
EmailAddress = "[email protected]",
Enc64FileContents = fileContents,
FileName = "test.txt"
};
XNamespace ns = "http://somenamespace/";
XElement emailDataElement = new XElement(ns + "EmailData");
emailDataElement.Add(new XElement(ns + "FileName", emailData.FileName));
emailDataElement.Add(new XElement(ns + "Enc64FileContents", emailData.Enc64FileContents));
emailDataElement.Add(new XElement(ns + "EmailAddress", emailData.EmailAddress));
var xml = emailDataElement.ToString(SaveOptions.DisableFormatting);
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/xml; charset=utf-8";
string response = wc.UploadString(URI, "POST", xml);
}
अब सेवा पक्ष पर, कुछ गुण निम्न स्क्रीनशॉट द्वारा दिखाए गए अनुसार शून्य हैं।
यह क्यों है कि FileName
सही मूल्य है लेकिन अन्य नहीं हैं?
+1 नीचे SSCCE लिंक के लिए कोड के रूप में,
[DataMember]
विशेषता मेंOrder
गुण सेट करने के लिए है :) –अपनी फ़ाइल कोई भी वर्ण के लिए मान्य नहीं शामिल करता है एक्सएमएल मूल्य? क्या आपने उन्हें एन्कोड करने की कोशिश की है? –
@ मारस यह एक सुपर सरल पाठ फ़ाइल है (केवल एक शब्द है)। मैंने बेस 64 स्ट्रिंग के बजाय सामान्य स्ट्रिंग भेजने का भी प्रयास किया और इससे कोई मदद नहीं मिली। –