如何保存字符串路径文件? [英] How Do I Save A String Path File?

查看:69
本文介绍了如何保存字符串路径文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在创建一些合同并在WCF服务中实现它们。我有以下代码:



Hi. I am creating some contracts and implementing them in a WCF service. I have the following code:

public interface IContent
    {
        [OperationContract]
        bool AddContent(string description, string location, int userID);
    }
    [DataContract]
    public class ContentData
    {
        [DataMember]
        public String Description;

        [DataMember]
        public String Location;
    }





实施方式如下:





It is implemented as thus:

public bool AddContent(string description, string location, int userID)
{
    ...
}





当我在测试中运行服务时客户端,并为位置传递路径,例如:



E:\ My Documents \Content\testcontent.txt



引发错误消息时出现DbEntityValidationException错误:位置字段是必需的。



在调试时,实现中的 location 参数是 null



当我尝试时为 location 传递一个普通字符串,而没有路径'\',例如如果我输入一个诸如这应该工作!之类的值,它可以工作:-( ..



如何解决反斜杠问题?我对什么感到困惑可能是错的。



When I run the service in the test client, and for location pass a path, such as:

E:\My Documents\Content\testcontent.txt

A DbEntityValidationException error is thrown with the Error Message: The Location field is required.

On debugging, the location parameter in the implementation comes in null.

When I try and pass a plain string for location without the path's '\', e.g. if I enter a value such as "This should work!", it works :-(..

How can is solve the backslash problem? I am confused on what could be wrong.

推荐答案

哦..我解决了这个问题。



路径需要转义在测试客户端。



http://connect.microsoft.com/VisualStudio/feedback/details/632374/wcf-test-client -sends-incorrect-null-value-as-string-type-value-for-wrongly-escaped-entered-values [ ^ ]



感谢所有相同..: - )
Oh.. I solved this.

The path needs to be escaped at the test client.

http://connect.microsoft.com/VisualStudio/feedback/details/632374/wcf-test-client-sends-incorrect-null-value-as-string-type-value-for-wrongly-escaped-entered-values[^]

Thanks all the same.. :-)


这篇关于如何保存字符串路径文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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